require(['init'], function () {
  //获取当前的id
  var uid,currentid;
  $.ajax({
    url:"/api/user/current",
    type:"get",
    async:false,
    success:function(data){
      uid=data.data.userid;
    }
  })
  $.ajax({
    url:"/api/student/user/"+uid,
    type:"get",
    async:false,
    success:function(data){
       currentid=data.data.studentuid;
    }
  })
  function getstudentjob() {
    $.ajax({
      url: '/api/task/student/'+currentid,
      type:'get',
      success: function (data) {
        var $listTable = $('#job_title').html('');
        $thead=$('<thead>\
          <tr class="enroll">\
            <th>'+i18next.t('table.no')+'</th>\
            <th>'+i18next.t('table.subject')+'</th>\
            <th>'+i18next.t('table.lessonsname')+'</th>\
            <th>'+i18next.t('table.teacher')+'</th>\
            <th>'+i18next.t('table.jobtitle')+'</th>\
            <th>'+i18next.t('table.schooltime')+'</th>\
            <th>'+i18next.t('table.jobstatus')+'</th>\
            <th>'+i18next.t('table.correctshomework')+'</th>\
            <th>'+i18next.t('table.handle')+'</th>\
          </tr>\
        </thead>').appendTo($listTable)
       var $tbody=$('<tbody></tbody>').appendTo($listTable)
       $.each(data.data,function(index,item){
          var teacheruid=item.teacheruid;
          var $tr=$('<tr class="enroll"></tr>').appendTo($tbody);
          $tr.append('<td>'+(index+1)+'</td>');
          $tr.append('<td>'+item.coursetypename+'</td>');
          $tr.append('<td>'+item.schedule+'</td>');
          var $teachername=$('<td></td>').appendTo($tr)
          $tr.append('<td>'+item.task+'</td>');
          $tr.append('<td>'+item.begintime+'</td>');
          var $submitstudetn=$('<td></td>').appendTo($tr);
          var $corrected=$('<td></td>').appendTo($tr);
          var $operation=$('<td></td>').appendTo($tr);
          var tname="";
          $.ajax({
             url: '/api/teacher/'+teacheruid,
             type:'get',
             success:function(json){
                $.each(json,function(index,it){
                  tname=it.lastname;
                if(teacheruid==it.teacheruid){
                  $('<a>'+tname+'</a>').appendTo($teachername);
                }
              })
             }
           })
           if(item.status==1){
             $('<a style="color:#398dee">'+i18next.t('table.submitted')+'</a>').appendTo($submitstudetn);
             $('<a class="btn btn-primary btn-sm btn-inverse" href="student_look.html?id='+item.id+'&schedule='+item.schedule+'&task='+item.task+'&taskid='+item.taskid+'&studentuid='+currentid+'&teacheruid='+item.teacheruid+'">'+i18next.t('table.look')+'</a>').appendTo($operation);
           }else if(item.status==0){
              var $submit=$('<a style="color:red" >'+i18next.t('table.nosubmit')+'</a>').appendTo($submitstudetn);
              $('<a class="btn btn-primary btn-sm btn-inverse" href="student_job.html?taskid='+item.taskid+'&studentuid='+currentid+'&id='+item.id+'">'+i18next.t('table.submit')+'</a>').appendTo($operation);
              $submit.parent().parent().addClass("submit");
           }
           if(item.corrected==1){
             var $marked=$('<a style="color:#398dee">'+i18next.t('table.marked')+'</a>').appendTo($corrected);
             $marked.parent().parent().addClass("marked");

           }else if(item.corrected==0){
             var $nomarked=$('<a style="color:red">'+i18next.t('table.nomarked')+'</a>').appendTo($corrected);
             $nomarked.parent().parent().addClass("nomarked");
           }else{
             $('<a style="color:red">'+i18next.t('table.nomarked')+'</a>').appendTo($corrected)
           }
        })
        $(".all").on('click',function(){
          $(this).addClass("hover")
          $('.submit').removeClass('hover');
          $('.nomarked').removeClass('hover');
          $('.marked').removeClass('hover');
          $tbody.find('.enroll').show();
        })
        $(".nomarked").on('click',function(){
          $(this).addClass("hover")
          $('.submit').removeClass('hover');
          $('.all').removeClass('hover');
          $('.marked').removeClass('hover');
          $tbody.find('.enroll')
          .show()
          $tbody.find('tr:not(.nomarked)')
          .hide();
        })
        $(".submit").on('click',function(){
          $(this).addClass("s_hover")
          $('.nomarked').removeClass('hover');
          $('.all').removeClass('hover');
          $('.marked').removeClass('hover');
          $tbody.find('.enroll')
          .show()
          $tbody.find('tr:not(.submit)')
          .hide();
        })
        $(".marked").on('click',function(){
          $(this).addClass("s_hover")
          $('.nomarked').removeClass('hover');
          $('.all').removeClass('hover');
          $('.submit').removeClass('hover');
          $tbody.find('.enroll')
          .show()
          $tbody.find('tr:not(.marked)')
          .hide();
        })
      }
     })
   }
 getstudentjob();
})
